package com.supreme.studyserver.config;

import com.supreme.common.constant.ConsoleColors;
import com.supreme.studyserver.config.handler.ColorHttpInterceptor;
import com.supreme.studyserver.config.handler.HttpInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        HandlerInterceptor handlerInterceptor = new HttpInterceptor();
        HandlerInterceptor redHttpInterceptor = new ColorHttpInterceptor(handlerInterceptor, ConsoleColors.RED_BOLD_BRIGHT);
        HandlerInterceptor yellowHttpInterceptor = new ColorHttpInterceptor(redHttpInterceptor, ConsoleColors.YELLOW_BOLD_BRIGHT);
        HandlerInterceptor greenHttpInterceptor = new ColorHttpInterceptor(yellowHttpInterceptor, ConsoleColors.GREEN_BOLD_BRIGHT);
        HandlerInterceptor blueHttpInterceptor = new ColorHttpInterceptor(greenHttpInterceptor, ConsoleColors.BLUE_BOLD_BRIGHT);
        HandlerInterceptor cyanHttpInterceptor = new ColorHttpInterceptor(blueHttpInterceptor, ConsoleColors.CYAN_BOLD_BRIGHT);
        HandlerInterceptor blackHttpInterceptor = new ColorHttpInterceptor(cyanHttpInterceptor, ConsoleColors.BLACK_BOLD_BRIGHT);
        registry.addInterceptor(blackHttpInterceptor).addPathPatterns("/**");
    }
}
